<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script type="text/javascript"  src="<c:url value='/scripts/global.js'/>"></script>
		<title>角色链接</title>
	</head>
	<e:View id="eView">
		<div id="Invisual Controls" style="display: none;" style="min-height: 40px; background-color: LemonChiffon;">
			<e:Dataset id="Dataset_RoleLink" datasetDefinition="DatasetDefinition.dsd" datasetRef="Dataset_RoleLink" pageSize="15" onBeforeChange="Dataset_RoleLink_onBeforeChange(dataset,field,value)">
				<e:Field name="id" maxLength="" label="id" dataType="string"></e:Field>
				<e:Field name="linkDesc" maxLength="" label="linkDesc" dataType="string"></e:Field>
				<e:Field name="linkName" maxLength="" label="链接名称" dataType="string" required="true"></e:Field>
				<e:Field name="menuId" maxLength="" label="menuId" dataType="string"></e:Field>
				<e:Field name="pxhm" maxLength="" label="pxhm" dataType="string"></e:Field>
				<e:Field name="roleId" maxLength="" label="roleId" dataType="string"></e:Field>
				<e:Field name="timeStamp" maxLength="" label="timeStamp" dataType="string"></e:Field>
				<e:Field name="menuName" maxLength="" label="菜单名称" dataType="string" required="true"></e:Field>
			</e:Dataset>
			
			
			<e:LookupDropDown id="LookupDropDown_Menu" path="/jsp/dropdown/menuDropdown.jsp" windowWidth="600" windowHeight="400" onSelect="LookupDropDown_Menu_onSelect(dropdown,iframe,text)" autoDropDown="true" fixed="true" windowCaption="选择菜单">
			</e:LookupDropDown>
			
			<e:Command id="Command_Save" action="com.longtop.framework.sys.role.web.RoleLinkAction" method="save" onExecuteSuccess="Command_Save_onExecuteSuccess(command)" validateRequired="true">
				<e:DatasetInfo name="DatasetInfo2" dataset="Dataset_RoleLink" alwayRefreshClient="false" submitType="changes"></e:DatasetInfo>
				<e:DatasetInfo name="DatasetInfo5" dataset="Dataset_Role" alwayRefreshClient="false" submitType="changes"></e:DatasetInfo>
			</e:Command>
			
			<e:Dataset id="Dataset_Role" datasetDefinition="DatasetDefinition.dsd" datasetRef="Dataset_Role" pageSize="1">
				<e:Field name="id" dataType="string" label="id" maxLength="" />
				<e:Field name="roleDesc" dataType="string" label="roleDesc" maxLength="" />
				<e:Field name="roleName" dataType="string" label="roleName" maxLength="" />
				<e:Field name="syfa" dataType="string" label="syfa" maxLength="" />
				<e:Field name="topOrgId" dataType="string" label="topOrgId" maxLength="" />
			</e:Dataset>
			
			<e:Command id="Command_Search" action="com.longtop.framework.sys.role.web.RoleLinkAction" method="search">
				<e:DatasetInfo name="DatasetInfo1" dataset="Dataset_RoleLink" alwayRefreshClient="true" submitType="none"></e:DatasetInfo>
			</e:Command>
		</div>
			
		<body>
			<e:Page id="ePage" action="com.longtop.framework.sys.role.web.RoleLinkAction" style="width: 98%; height: 100%;" >
				<table style="width: 100%; height: 100%;" border="0" cellpadding="2" cellspacing="2" width="100%">
					<tbody>
						<tr>
							<td width="100%" height="10%" align="left" valign="top" colspan="2">
								<e:Panel id="Panel_Action" style="width: 100%; height: 100%" caption="保存" captionIcon="/images/list_win.gif" captionStyle="color:#888888" allowFold="false" showArrowButton="false" showCaptionBar="false">
										<table>
											<tr align="right">
												<td width="1%" align="left" nowrap="nowrap">
													<e:Button id="Button_Close" 
														caption="返回" icon="/images/undo.gif" onClick="Button_Close_onClick()" style="width: 70px; height: 22px">
													</e:Button>&nbsp;
													<e:Button id="Button_Save" 
														caption="保存" icon="/images/submit.gif" onClick="Button_Save_onClick()" style="width: 70px; height: 22px" enabled="role:6">
											    	</e:Button>
													<e:Text id="Text_RoleId" style="display:none"></e:Text>
												</td>
											</tr>
										</table>
								</e:Panel>
							</td>
						</tr>
						
						<tr>
							<td width="100%" height="90%" valign="top" align="left" nowrap="nowrap">
								<e:Panel id="Panel_RoleLink" style="width: 100%; height: 100%" caption="角色链接信息" captionIcon="/images/list_win.gif" captionStyle="color:#888888" showArrowButton="false">
									<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2" width="100%" align="center">
										<tbody>
											<tr align="right">
												<td width="1%" align="left" nowrap="nowrap" height="27px">
													<e:RecordNavigator id="RecordNavigator_RoleLink" dataset="Dataset_RoleLink" style="width: 0px" showNavigatorButton="false">
														<e:RecordButton id="RecordButton_InsertRoleLink" label="新增明细" onClick="RecordButton_InsertRoleLink_onClick()" icon="/images/add.gif" enabled="role:3"></e:RecordButton>
														<e:RecordButton id="RecordButton_DeleteRoleLink" label="删除明细" onClick="RecordButton_DeleteRoleLink_onClick()" icon="/images/delete.gif" enabled="role:5"></e:RecordButton>
													</e:RecordNavigator>
												</td>
											</tr>
											<tr>
												<td>
													<e:Grid id="Grid_RoleLink" style="width: 100%; height: 400px;" dataset="Dataset_RoleLink" showIndicator="false" showIndex="false" showFilterRow="false">
														<e:Column name="pxhm" label="排序号" field="pxhm"  style="width:20%" ></e:Column>
														<e:Column name="linkName" label="链接名称" field="linkName" dataType="string" style="width:20%"></e:Column>
														<e:Column name="menuName" label="菜单名称" field="menuName"  style="width:20%" dropDown="LookupDropDown_Menu"></e:Column>
														<e:Column name="linkDesc" label="链接描述" field="linkDesc" dataType="string" style="width:39%"></e:Column>
													</e:Grid>
												</td>
											</tr>
										</tbody>
									</table>
								</e:Panel>	
							</td>
						</tr>
					</tbody>
				</table>
			</e:Page>
		</body>
		
		<script type="text/javascript">
		
			//返回
			function Button_Back_onClick(){
				var tabName = "<%=request.getParameter("openerTabName") %>";
				returnToParentTab(tabName,true);
			}
			//保存
			function Button_Save_onClick(){
				var roleId = "<%=request.getParameter("roleId")%>";
				if(roleId != null && roleId != ""){
					var cmd = $J("Command_Save");
					cmd.parameters.setValue("roleId",roleId);
					cmd.execute();
				}
			}
			
			//新增链接
			function RecordButton_InsertRoleLink_onClick(){
				
				//得到已有的记录数
				var count = 0;
				Dataset_RoleLink.disableControls();
				try {
					var record = Dataset_RoleLink.getFirstRecord();
					while (record != null) {
						count++;
						record = record.getNextRecord();
					}
				}
				finally {
					Dataset_RoleLink.enableControls();
					Dataset_RoleLink.refreshControls();
				}
			
				if(count == 8){
					alert("首页链接数不能超过8个！");
					return;
				}
				Dataset_RoleLink.insertRecord();
				//得到角色ID
				var txtRoleId = $J("Text_RoleId");
				var roleId = txtRoleId.getValue();
				Dataset_RoleLink.setValue("roleId",roleId);
				Dataset_RoleLink.setValue("pxhm",(count).toString(10));
			}
			
			//删除链接
			function RecordButton_DeleteRoleLink_onClick(){
				if(window.confirm("您确定要删除当前的记录吗？")){
					Dataset_RoleLink.deleteRecord();
				}
			}
			//删除链接
			function RecordButton_DeleteYjtp_onClick(){
				if(window.confirm("您确定要删除当前的记录吗？")){
					Dataset_RoleYjtp.deleteRecord();
				}
			}
			//选择菜单
			function LookupDropDown_Menu_onSelect(dropdown,iframe,text){
				var ds = $J(iframe.Dataset_Menu);
				var node = $J(iframe.DataTree_Menu).getCurrentNode();
				if(ds && node!=null&& null&& node.level > 1){//除去根节点
				    var record = ds.getCurrentRecord();
				    if(typeof record != "undefined"){
				    	//验证menuId是否重复
				    	var menuId = record.getValue("id");
				    	var menuName = record.getValue("menuName");
				    	//如果存在重复,则返回值作为信息提示用户。
				    	var recordMenuId = Dataset_RoleLink.locate(["menuId"],[menuId]);
				        if (recordMenuId != null ) {
				        	alert("菜单名称[" + menuName + "]已存在！");
				            return ;
				        }
				   		Dataset_RoleLink.getCurrentRecord().setValue("menuId",menuId);
				   		Dataset_RoleLink.getCurrentRecord().setValue("menuName",menuName);
				   	}
				}
			}
			
			//验证链接是否重复
			function Dataset_RoleLink_onBeforeChange(dataset,field,value){
				if (value == null || trim(value) == "") return;
			
			    //如果当前字段是linkName，且数据发生变化，且是新增或插入状态，则进行验证
			    if (field.name == "linkName") {
			            
			       	var record = Dataset_RoleLink.locate(["linkName"],[trim(value)]);
			       	
			        //如果存在重复,则返回值作为信息提示用户。
			        if (record != null ) {
			            return "链接名称[" + value + "]已存在！";
			        }
			    }
			    if (field.name == "pxhm") {
			       	var record = Dataset_RoleLink.locate(["pxhm"],[trim(value)]);
			        //如果存在重复,则返回值作为信息提示用户。
			        if (record != null ) {
			            return "排序号[" + value + "]已存在！";
			        }
			    }
			}
			
			//保存成功
			function Command_Save_onExecuteSuccess(command){
				if(command.parameters.getValue("refresh") == "true"){
					//得到角色ID
					var txtRoleId = $J("Text_RoleId");
					var roleId = txtRoleId.getValue();
					var cmd = $J("Command_Search");
					cmd.parameters.setValue("roleId",roleId);
					cmd.execute();
					
					alert("操作成功！");
				}
			}
			//返回
			function Button_Close_onClick(){
				var tabName = "<%=request.getParameter("openerTabName") %>";
				returnToParentTab(tabName,false); 
			}
		
		</script>
	</e:View>

</html>